﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZK.BLL;
using ZK.BLL.Config;
using ZK.Entity;

namespace ZK.Client
{
    public partial class FrmPassword : Form
    {
        public FrmPassword()
        {
            InitializeComponent();
        }

        private void FrmPassword_Load(object sender, EventArgs e)
        {
            txtUserId.Text = TempConfig.GetConfig().UserId;
        }

        private void btnSure_Click(object sender, EventArgs e)
        {
            var list= UserInfoBLL.Instance.GetList();
 
            string password = txtPassword.Text.Trim();

            UserInfo userInfo = null;

            if (list.Count > 0)
            {
                userInfo = list.FirstOrDefault(s => s.UserId == txtUserId.Text.Trim());
            }
 
            if (userInfo == null)
            {
              
                MessageBox.Show("用户不存在！");
                return;
            }
            else if (userInfo.Password != password)
            {
                MessageBox.Show("密码不正确！");
                return;
            }
            else {
                TempConfig.GetConfig().UserId = userInfo.UserId;
                TempConfig.GetConfig().EditConfig();
                Class_Config.UserInfo = userInfo;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }

         
 
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }

        private void txtPassword_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnSure_Click(null,null);
            }
        }

        private void FrmPassword_Resize(object sender, EventArgs e)
        {
            ZK.MyControl.SetWindowRegion.SetWindowSadius(10, this);
        }
 
    }
}
